#!/bin/bash
#!/bin/bash

##shell options
working_dir=$1
sample_list=$2
n_jobs=$3

gatk_HaplotypeCaller(){
#Tools
gatk=/picb/lilab/tools/gatk-4.2.6.1/gatk

#Reference dir
reference=/picb/lilab5/share_data/ref/hg38/

if [ ! -d $2/gvcf ]
then mkdir -p $2/gvcf
fi

if [ ! -d $2/gvcf/tmp ]
then mkdir -p $2/gvcf/tmp/$1
fi

if [ ! -d $2/realign ]
then mkdir -p $2/realign
fi 

#Variants Calling
time $gatk HaplotypeCaller \
    -ERC GVCF \
    -R $reference/Homo_sapiens.GRCh38.dna.primary_assembly.fa \
    -I $2/bam/marked_dup_bam/$1_sorted_markdup.bam \
    -O $2/gvcf/$1.HC.g.vcf.gz \
    -bamout $2/realign/$1.realign.bam \
    --tmp-dir $2/gvcf/tmp/$1
rm -rf $2/gvcf/tmp/$1

}

export -f gatk_HaplotypeCaller

parallel --jobs ${n_jobs} gatk_HaplotypeCaller :::: ${sample_list} ::: ${working_dir} 



